package ebcs.scan.controller.sys;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import ebcs.app.auto.transmodel.sys.TestReqModel;
import ebcs.scan.bean.sys.FileStorageBean;
import ebcs.scan.bean.sys.SysUserInfor;
import ebcs.scan.common.consts.KPlatSysConsts;
import ebcs.scan.service.sys.fileStorage.FileStorageService;
import jplat.core.trans.JAppBaseService;
import jplat.core.trans.JAppContext;
import jplat.core.trans.JAppContextFactory;
import jplat.error.exception.JSystemException;
import jplat.error.exception.JTransException;
 

/***
 *  测试管理
 * @author chenzhuo
 * @comment 
 */
@Controller
public class TestManagerCtrl extends JAppBaseService
{
	private Logger logger = Logger.getLogger(TestManagerCtrl.class);
	protected JAppContextFactory serviceFactory = new JAppContextFactory(); 
	
	@Autowired 
	private FileStorageService fileService;
	 
	/**
	 * 上传项目
	 */
	@RequestMapping("/sys/testuploadfile.do")
	@ResponseBody
	public void uploadfile(HttpServletRequest request, HttpServletResponse response)
			throws JTransException, JSystemException {
		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
		TestReqModel testReq = context.obtainReqModel(TestReqModel.class);
		SysUserInfor sysuser = context.getUserInfo();
		try {
			byte[] uploadByte = Base64.decodeBase64(testReq.getFileBase64Data());
 			FileStorageBean fileStorage = new FileStorageBean();
			fileStorage.setEntityName("entityName");
			fileStorage.setEntityNo("1001");
			fileStorage.setEntityType("1111");
			fileStorage.setStorageName("testFile.xls");
			fileStorage.setUserNo(sysuser.getUserNo());
 			fileStorage.setFileData(uploadByte); 
			String storageId = fileService.writeToFileStorage(fileStorage);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Map rsModel = new HashMap();
  		context.buildAppResponse(null);
	}
	
	
	/**
	 * 
	 */
 	@RequestMapping("/prm/testPermission.do")
	public void testPermission( HttpServletRequest request,HttpServletResponse response ) throws JTransException, JSystemException{
		JAppContext context = serviceFactory.buildAppContextWithUser(request,response);		//buildAppContextWithUser 自带客户信息.
		Map rsModel = new HashMap();
  		context.buildAppResponse(null);
 	}
}